# from usart_stm32.usart import get_car_data, send_car_data
# from usart_stm32.usart_config import ser
from server_api import get_work, post_order_state, has_work, post_temp_hum, post_point, post_warning
from calculate.car_operator import Operate
from calculate.car_direction import pos_to_direction, is_arrive

server = 'http://106.53.119.46'
car_id = 1
car_pt = '113.08383,28.321184'  # 从stm32获取
i_temp = 7788
i_hum = 8877

oid = 1
warning_flag = 0

def test_has_work():
    if has_work(server):
        print("has task")
    else:
        print("no task")

def test_get_work():
    global oid
    get_task_flag, oid, path = get_work(server, car_pt, car_id, i_temp, i_hum)
    if get_task_flag == 1:
        print("接受任务成功")
    elif get_task_flag == 0:
        print("暂无待配送的订单")
    else:
        print("接收任务失败")

def test_post_temp_hum():
    post_temp_hum(server, oid, i_temp, i_hum)

def test_post_point():
    if post_point(server, oid, car_pt):
        print('位置信息更新成功')
    else:
        print('位置信息更新失败')

def test_post_warning():
    post_warning(server, car_id, warning_flag)

def test_post_order_state():
    if post_order_state(server, oid, 0):
        print("订单状态更新成功")
    else:
        print("订单状态更新失败")

if __name__ == '__main__':
    post_temp_hum(server, oid, i_temp, i_hum)
    post_point(server, oid, car_pt)
    post_warning(server, car_id, oid, warning_flag)